package com.zyy;

/**
 * @ProjectName: concurrent
 * @Package: com.zyy
 * @ClassName: Daemon
 * @Author: ZHAYUYAO
 * @Description: 守护线程
 * @Date: 2019/9/15 21:53
 * @Version: 1.0
 */
public class Daemon {
    static class MyThread extends Thread {
        MyThread(String name) {
            super(name);
        }

        @Override
        public void run() {
            String currentThreadName = Thread.currentThread().getName();
            try {
                while (!isInterrupted()) {
                    System.out.println(currentThreadName+" is running...");
                }
            } finally {
                System.out.println("......finally");
            }

        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread("zyy");
        myThread.setDaemon(true);
        myThread.start();
        Thread.sleep(100);
//        myThread.interrupt();//中断子线程，才会执行finally
    }
}
